package com.mingtu.jgspatrol.fragment;

import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.StringUtils;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.hjq.gson.factory.GsonFactory;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.mingtu.common.base.BaseBindingFragment;
import com.mingtu.common.callback.StringDialogCallback;
import com.mingtu.common.utils.Constant;
import com.mingtu.common.viewpager.LazyViewPager.LazyFragmentPagerAdapter;
import com.mingtu.jgspatrol.R;
import com.mingtu.jgspatrol.adapter.NavAdapter4;
import com.mingtu.jgspatrol.bean.MyReportRecordBean;
import com.mingtu.jgspatrol.databinding.FragmentNav4Binding;
import com.mingtu.jgspatrol.utils.MyConstant;

import java.util.HashMap;
import java.util.List;

public class Nav4Fragment extends BaseBindingFragment<FragmentNav4Binding> implements LazyFragmentPagerAdapter.Laziable {
    
    private int currentPage = 1;
    private boolean isLoadMore = true;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_nav4;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext().getApplicationContext());
        binding.recycler.setLayoutManager(linearLayoutManager);

        //添加自定义分割线
        DividerItemDecoration divider = new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL);
        divider.setDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.shape_dive_line));
        binding.recycler.addItemDecoration(divider);

        NavAdapter4 navAdapter4 = new NavAdapter4(getContext());
        binding.recycler.setAdapter(navAdapter4);

    }

    @Override
    protected void getData() {
//        getMsgList(1);
    }


    /**
     * 首页消息通知列表
     */
    private void getMsgList(int pageNum) {
        if (pageNum == 1) {
            currentPage = 1;
        }
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("curPage", pageNum);
        hashMap.put("pageSize", Constant.PAGE_SIZE);
        String str = GsonUtils.toJson(hashMap);
        OkGo.<String>post(MyConstant.POST_INDEX_REPORT_TASK)
                .tag(this)
                .upJson(str)
                .execute(new StringDialogCallback(getActivity()) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        if (!StringUtils.isEmpty(result)) {

                            try {
                                Gson gson = GsonFactory.getSingletonGson();
                                MyReportRecordBean myReportRecordBean = new MyReportRecordBean();
                                myReportRecordBean = gson.fromJson(result, MyReportRecordBean.class);

                                List<MyReportRecordBean.PageBean.ListBean> dataBeans = myReportRecordBean.getPage().getList();


                            } catch (JsonSyntaxException e) {
                                e.printStackTrace();
                            }


                        }
                    }
                });

    }

    /**
     * 刷新数据
     */
    public void refresh() {
//        getMsgList(1);
    }
}